<template>
  <div class="login">
    <el-card header="请先登录" class="login-card">
      <el-form @submit.native.prevent="login">
        <el-form-item label="用户名">
          <el-input v-model="model.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="model.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" native-type="submit" style="width: 100%;">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { getlogin } from '@/api/login'
export default {
  name: "Login",
  data() {
    return {
      model: {}
    };
  },
  methods: {
    async login() {
      let data = this.model
      let res = await getlogin(data) 
      localStorage.setItem('admin_token',res.data.token)
      this.$router.push('/')
      this.$message({
        type: 'success',
        message: '登陆成功'
      })
    }
  }
};
</script>

<style lang="less" scoped>
  .login-card{
    width: 25rem;
    margin: 5rem auto;
  }
</style>